<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>网上购票</title>
<link rel="stylesheet" href="resources/css/frozen.css">
<link rel="stylesheet" href="resources/css/main.css">
<script src="resources/js/config.js"></script>
<style>
#verify-code {
	padding-right: 100px;
}
#verify {
    width: 100px;
    height: 44px;
    position: absolute;
    top: 0;
    right: 0;
}
#verify img {
    margin: 6px;
}
</style>
<script src="resources/lib/zepto.min.js"></script>
<script src="resources/js/frozen.js"></script>
<script src="resources/js/config.js"></script>
<script src="resources/js/main.js?v=1"></script>

</head>
<body ontouchstart="">
	<header class="ui-header ui-header-positive ui-border-b">
		<h1>登录</h1>
	</header>
	<footer class="ui-footer ui-footer-btn">
		<ul id="footer" class="ui-tiled ui-border-t">
			<li data-href="index.html" class="ui-border-r">
				<div>查询购票</div>
			</li>
			<li data-href="order.html" class="ui-border-r">
				<div>订单查询</div>
			</li>
			<li data-href="member.html">
				<div>会员中心</div>
			</li>
		</ul>
	</footer>
	<section class="ui-container">
		<section class="ui-selector">
			<br/>
			<div class="ui-form ui-border-t">
				<form action="#">
					<div class="ui-form-item ui-form-item-show ui-border-b">
						<label for="username">用户名</label>
						<input id="username" type="text" placeholder="用户名或手机号" value="">
					</div>
					<div class="ui-form-item ui-form-item-show ui-border-b">
						<label for="password">密码</label>
						<input id="password" type="password" placeholder="6-12位字母或数字" value="">
					</div>
				</form>
			</div>
			<div class="ui-btn-wrap">
				<button id="btn-login" class="btn-group ui-btn-lg ui-btn-primary">
					登&nbsp;&nbsp;&nbsp;&nbsp;录
				</button>
				<button id="btn-register" class="btn-group ui-btn-lg ui-btn-primary">
					注&nbsp;&nbsp;&nbsp;&nbsp;册
				</button>
				
				<button id="btn-forget-password" class="btn-group ui-btn-lg ui-btn-primary">
					忘记密码
				</button>
			</div>
		</section>
	</section>
	
	<div id="loading" class="ui-loading-block hide">
		<div class="ui-loading-cnt">
			<i class="ui-loading-bright"></i>
			<p>努力加载中...</p>
		</div>
	</div>

<script>
(function (){
	/* -------------------- 判断是否为微信浏览器 -------------------- */

	if(appConfig.isWeixin) {
		$("#btn-weixin-login").show();
	}

	/* -------------------- 根据sessionStorage中的值，初始化界面 -------------------- */
	
	if(!!sessionStorage.message) {
		showInfoTip(sessionStorage.message);
		sessionStorage.message = "";
	}
	
	/* -------------------- 根据localStorage中的值，初始化界面 -------------------- */
	
	// 初始化起点站查询条件
	if(!!localStorage.mobile) {
		$("#username").val(localStorage.mobile);
		$("#password").focus();
	} else {
		$("#username").focus();
	}
	
	/* -------------------- 初始化 -------------------- */
	
	// 底部主菜单初始化
	initFooter("#footer");
	
	// 登录按钮点击事件
	$("#btn-login").tap(function(){
		var username = $.trim($("#username").val());
		var password = $("#password").val();
		
		if(!username) {
			showInfoTip("请输入用户名或手机号");
			return;
		}
		
		if(!password) {
			showInfoTip("请输入密码");
			return;
		}
		
		doLogin();
	});

	// 注册按钮点击事件
	$("#btn-register").tap(function(){
		location.href = "register.html";
	});
	
	// 忘记密码按钮点击事件
	$("#btn-forget-password").tap(function(){
		location.href = "forgetPassword.html";
	});
})();

// 登录
function doLogin() {
	ajax({
		url: appConfig.baseUrl + "/Login.go",
		data: {
			method: "doMemberLogin",
			username: $.trim($("#username").val()),
			password: $.trim($("#password").val())
		},
		failMessage: "登录失败，请重试",
		success: function(data) {
			hideLoading("#loading");
			if(!!data.success && data.success==true || data.success=="true") {;
				sessionStorage.memberId = data.userid;
				sessionStorage.memberName = data.name;
				sessionStorage.mobile = data.mobile;
				sessionStorage.idCard = data.idcard == null? '' : data.idcard;
				sessionStorage.score = data.score;
				
				localStorage.mobile = sessionStorage.mobile;

				if(!!sessionStorage.backUrl) {
					location.href = sessionStorage.backUrl;
				} else {
					history.back();
				}
			} else {
				showInfoTip("登录失败");
				return;
			}
		}
	});
}
</script>
</body>
</html>